package com.example.socialwebserver.controller;

import com.example.socialwebserver.pojo.AdminDAO;
import com.example.socialwebserver.pojo.LoginDTO;
import com.example.socialwebserver.pojo.ServerResult;
import com.example.socialwebserver.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@CrossOrigin
public class AdminController {
    @Autowired
    AdminService adminService;
    @RequestMapping("/admin/SelectAll")
    public ServerResult SelectAll(){
        List<AdminDAO> adminDAOS = adminService.SelectAll();
        ServerResult serverResult = new ServerResult(0,"成功",adminDAOS);
        return serverResult;
    }

    @RequestMapping("/admin/adminLogin")
    public ServerResult adminLogin(LoginDTO loginDTO){
        Integer integer = adminService.adminLogin(loginDTO);
        ServerResult serverResult;
        if(integer>0)
        {
            serverResult = new ServerResult(0, "管理员登陆成功", integer);
        }
        else {
            serverResult = new ServerResult(101, "管理员登录失败", null);
        }
        return serverResult;
    }

}
